﻿#include "MdbIndexComp.h"
#include <string.h>


namespace mdb
{
	bool TickEqualForInstrumentIDIndex::operator()(const Tick* const left, const Tick* const right) const
	{
		return strcmp(left->InstrumentID, right->InstrumentID) == 0;
	}
	bool TickLessForInstrumentIDIndex::operator()(const Tick* const left, const Tick* const right) const
	{
		if (strcmp(left->InstrumentID, right->InstrumentID) < 0)
			return true;
		else if (strcmp(left->InstrumentID, right->InstrumentID) > 0)
			return false;
		return false;
	}

	bool BarEqualForInstrumentIDIndex::operator()(const Bar* const left, const Bar* const right) const
	{
		return left->TradingDay == right->TradingDay && strcmp(left->ExchangeID, right->ExchangeID) == 0&& strcmp(left->InstrumentID, right->InstrumentID) == 0;
	}
	bool BarLessForInstrumentIDIndex::operator()(const Bar* const left, const Bar* const right) const
	{
		if (left->TradingDay < right->TradingDay)
			return true;
		else if (left->TradingDay > right->TradingDay)
			return false;
		if (strcmp(left->ExchangeID, right->ExchangeID) < 0)
			return true;
		else if (strcmp(left->ExchangeID, right->ExchangeID) > 0)
			return false;
		if (strcmp(left->InstrumentID, right->InstrumentID) < 0)
			return true;
		else if (strcmp(left->InstrumentID, right->InstrumentID) > 0)
			return false;
		return false;
	}

	bool BarEqualForTradingDayIndex::operator()(const Bar* const left, const Bar* const right) const
	{
		return left->TradingDay == right->TradingDay ;
	}
	bool BarLessForTradingDayIndex::operator()(const Bar* const left, const Bar* const right) const
	{
		if (left->TradingDay < right->TradingDay)
			return true;
		else if (left->TradingDay > right->TradingDay)
			return false;
		return false;
	}

}
